<?php

namespace app\admin\controller;
use app\BaseController;
use app\admin\model\Live;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;

class Index extends BaseController
{
    public function initialize()
    {
        echo "11";
        die;
    }
    public function index(){
        
        return view();
    }
    public function list(){
        $id = Request::param('id');

        if(empty($id)){
                $ar=Live::select();
                view::assign('list',$ar);
                return view::fetch('');
            }else{
                $result =Live::destroy($id);
                return json(['code'=>200,'msg'=>'删除成功']);
        }
    }
    public function add(){
        $data = Request::param();

        if(!empty($data)){
            $result = Live::create($data);
            return json(['code'=>200,'msg'=>'新增成功']);
            
        }else{
            return view();
        }
    }
    public function edit(){
        if(Request::isAjax()){
            $add = Request::param();
            $result = Live::update($add);
            return json(['code'=>200,'msg'=>'编辑成功']);
        }else{
            $id = Request::param('id');
            $date = Live::find($id);
            view::assign('date',$date);
            return view();
        }
    }
    public function user(){
        
        return view();
    }

}